clear;
close all;
paths;

load('soln.mat');
load('data.mat');


%% Shutting down learning

T = height(data);
pi_e_counter = NaN(2,T);
regressor = [ones(T-1,1), data.inflation(1:T-1)];
[b_pi, ~, resid] = regress(data.inflation(2:T), regressor);

pi_e_counter(:,1) = infl_e(2:3,1);

kgain = [1; 1];

sig = 1;
for t = 1:30
    omega = b_pi(2)^2 * sig + var(resid);
    sigma = omega + soln.hh_sd_w(2)^2;
    kgain(1)  = omega/sigma; 
    sig   = omega - kgain(1)*omega;
end


for tt = 2:T

    pi_e_counter(:,tt) = b_pi(1)*[1;1] + b_pi(2)*kgain.*signal(2:3,tt) + b_pi(2)*([1;1]-kgain).*pi_e_counter(:,tt-1);

end


t = datetime(1977,12,31) + calquarters(1:1:T);

figure;
hold on;
%plot(t, y(:,2)','Marker','diamond', 'LineWidth',1, 'Color', [0 0.4470 0.7410]); 
plot(t, infl_e(2,:), '-', 'LineWidth',2.5, 'Color', [0 0.4470 0.7410]); 
plot(t, pi_e_counter(1,:), ':', 'LineWidth',2.5, 'Color', '#396684'); 
xtickformat('yyyy');
legend('boxoff');
legend({'non-college purified',  'non-college couterfactual'},'fontsize', 12); box off;
ylabel('1-year ahead Inflation expectations', 'fontsize', 15);
set(gcf,'position',[0,0,1000,500]); fontsize(gcf,scale=1.5);
style = hgexport('factorystyle'); style.Color = 'gray';
hgexport(gcf,"figures/1_yr_counterfactual_nc.eps",style);


figure;
hold on;
%plot(t, y(:,3)','Marker','square', 'LineWidth',1, 'Color', [0.8500 0.3250 0.0980]); 
plot(t, infl_e(3,:), '-', 'LineWidth',2.5,'Color', [0.8500 0.3250 0.0980]); 
plot(t, pi_e_counter(2,:), ':', 'LineWidth',2.5,'Color', '#a86548'); 
xtickformat('yyyy');
legend('boxoff');
legend({'college purified', 'college couterfactual'},'fontsize', 12); box off;
ylabel('1-year ahead Inflation expectations', 'fontsize', 15);
set(gcf,'position',[0,0,1000,500]); fontsize(gcf,scale=1.5);
style = hgexport('factorystyle'); style.Color = 'gray';
hgexport(gcf,"figures/1_yr_counterfactual_cd.eps",style);